var isPhone = (window.navigator.platform != "Win32");
var isAndroid = (window.navigator.userAgent.indexOf('Android') >= 0) ? true : false;
document.write('<script src="data/webservice.js"></script>'); //web接口

RequestKey = 'FDDBCAA11500948183F0299431B2B571'
ZV_EMPLOYEE_NUMBER = localStorage.getItem("ZV_EMPLOYEE_NUMBER");
var UrlClient = "http://mpservice.ceair.com/WebServiceClient?RequestKey=FDDBCAA11500948183F0299431B2B571"; //正式地址
//var UrlClient = "http://mgstest.ceair.com:8080/WebServiceClient?RequestKey=FDDBCAA11500948183F0299431B2B571"; //测试地址
/**
 * 密钥
 */
var KEY11 = "1";
var KEY22 = "1";
var KEY33 = "1";
/**@Function strToJson
  @param {Object} str
   字符串转换json方法
 */
function strToJson(str) {
  var json = eval('(' + str + ')');
  return json;
}
/*
 * 电话号码判断
 */
function getNum(text) {
  var value = text.replace(/[^0-9]/ig, ",");
  var str = "";
  value = value.split(",");
  for (var i = 0; i < value.length; i++) {
    if (value[i].length == 11) {
      str += "," + value[i];
    }
  }
  str = str.substring(1, str.length);
  str = str.split(",");
  str = str[str.length - 1]
  return str;
}
/*
 * 电话号码判断end
 */
function LoadParent() {
  var str = '<div id="zvmainp" class="zvmainp"></div><div id="loadBox" style="display:block"><div id="loadbg"><img src="images/nobg.png" id="nobgpng"></div><div><img src="images/loadingimg.png" id="loadingimg"></div></div>';
  //$("#content").append(str);
}
/**
 * @param String inWndName 新窗口名称
 * @param String html		新窗口路径
 * @param String inAniID	打开动画
 * @param String f
 */
function openNewWin(inWndName, html, inAniID, f) {
  if (inAniID == 0) {
    uexWindow.open(inWndName, '0', html, 0, '', '', (f) ? f : 0);
    return;
  }
  if (inAniID)
    uexWindow.open(inWndName, '0', html, inAniID, '', '', (f) ? f : 0);
  else
    uexWindow.open(inWndName, '0', html, 10, '', '', (f) ? f : 0);
}

/**
 * 关闭窗口
 * @param string n 关闭窗口动画，默认-1
 */
function winClose(n) {
  if (n) {
    uexWindow.close(n);
    return;
  }
  if (parseInt(n) == 0) {
    uexWindow.close(n);
    return;
  }
  uexWindow.close(-1);
}
/**
 * 输出loag
 * @param String s 需要输出的信息
 * @param String a 添加的标注信息
 */
function logs(s, a) {
  if (typeof s == 'object') {
    s = JSON.stringify(s);
  }
  a = a ? a : "";
  if (!isPhone) {
    console.log(a + s);
  } else {
    uexLog.sendLog(a + s);
  }
}

/**
 * localStorage保存数据
 * @param String key  保存数据的key值
 * @param String value  保存的数据
 */
function setLocVal(key, value) {
  window.localStorage[key] = value;
}

/**
 * 根据key取localStorage的值
 * @param Stirng key 保存的key值
 */
function getLocVal(key) {
  if (window.localStorage[key])
    return window.localStorage[key];
  else
    return "";
}

/**
 * 清除缓存
 * @param Striong key  保存数据的key，如果不传清空所有缓存数据
 */
function clearLocVal(key) {
  if (key)
    window.localStorage.removeItem(key);
  else
    window.localStorage.clear();
}

/**
 * alert 和 confirm 弹出框
 * @param String str 提示信息语
 * @param Function callback confirm的回调函数
 */
function $alert(str, callback) {
  if (callback) {
    uexWindow.cbConfirm = function(opId, dataType, data) {

      if (data == 0) {
        alert(callback);
        callback();
      }

    }
    uexWindow.confirm('提示信息', str, ['确定', '取消']);
  } else
    uexWindow.alert('提示信息', str, '确定');
}

/**
 * alert 和 confirm 弹出框
 * @param String str 提示信息语
 * @param Function callback confirm的回调函数
 */
function score_yes(str, callback) {
  if (callback) {
    uexWindow.cbConfirm = function(opId, dataType, data) {

      if (data == 0) {
        callback();
      }

    }
    uexWindow.confirm('提示信息', str, ['确定', '取消']);
  } else
    uexWindow.alert('提示信息', str, '确定');
}
/**
 * 在其他窗口中执行指定主窗口中的代码
 * @param String wn  需要执行代码窗口的名称
 * @param String scr 需要执行的代码
 */
function uescript(wn, scr) {
  uexWindow.evaluateScript(wn, '0', scr);
}

/**
 * 在其他窗口中执行指定浮动窗口中的代码
 * @param String wn  需要执行代码浮动窗口所在的主窗口的名称
 * @param String pn  需要执行代码的浮动窗口的名称
 * @param String scr 需要执行的代码
 */
function ueppscript(wn, pn, scr) {
  uexWindow.evaluatePopoverScript(wn, pn, scr);
}

/**
 * 给DOM对象赋值innerHTML
 * @param String id 对象id或者对象
 * @param String html html字符串
 * @param String showstr 当html不存在时的提示信息语
 */
function setHtml(id, html, showstr) {
  var showval = isDefine(showstr) ? showstr : "";
  if ("string" == typeof(id)) {
    var ele = $$(id);
    if (ele != null) {
      ele.innerHTML = isDefine(html) ? html : showval;
    } else {
      alert("没有id为" + id + "的对象");
    }
  } else if (id != null) {
    id.innerHTML = isDefine(html) ? html : showval;
  }
}

/**
 * 设置平台弹动效果
 * @param int sta   0=无弹动效果   1=默认弹动效果  2=设置图片弹动
 * @param Function downcb 下拉
 * @param Function upcb   上拖
 */
function setPageBounce(sta, downcb, upcb) {
  if (sta == 0) return;
  var color = "#FFF";
  if (sta == 1) {
    var s = ['0', '0'];
    var str = '';
    uexWindow.onBounceStateChange = function(type, status) {
      if (downcb && type == 0 && status == 2) downcb();
      if (upcb && type == 1 && status == 2) upcb();
    }

    uexWindow.setBounce("1");

    if (downcb) {
      s[0] = '1';
      uexWindow.notifyBounceEvent("0", "1");
    }
    if (color) {
      uexWindow.showBounceView("0", color, s[0]);
    } else {
      uexWindow.showBounceView("0", "rgba(255,255,255,0)", s[0]);
    }


    if (upcb) {
      s[1] = '1';
      uexWindow.notifyBounceEvent("1", "1");
    }
    if (color) {
      uexWindow.showBounceView("1", color, s[1]);
    } else {
      uexWindow.showBounceView("1", "rgba(255,255,255,0)", s[1]);
    }
    //	uexWindow.showBounceView("1","rgba(255,255,255,0)",s[1]);
  }
  if (sta == 2) {
    uexWindow.onBounceStateChange = function(type, status) {
      uexLog.sendLog("type=" + type + "||status=" + status);
      if (downcb && type == 0 && status == 2) downcb();
      if (upcb && type == 1 && status == 2) upcb();
    }
    uexWindow.setBounce("1");

    var inJson = '{"imagePath":"res://reload.png","textColor":"#530606","pullToReloadText":"拖动刷新","releaseToReloadText":"释放刷新","loadingText":"加载中，请稍等"}'
    if (downcb) {
      uexWindow.setBounceParams('0', inJson);
      uexWindow.showBounceView('0', color, 1);
      uexWindow.notifyBounceEvent('0', 1);
    }
    if (upcb) {
      uexWindow.setBounceParams('1', inJson)
      uexWindow.showBounceView('1', color, 1);
      uexWindow.notifyBounceEvent('1', 1);
    }
  }
}

/***
 * 使弹动重置为初始位置
 * @param String type 弹动的类型 0-顶部弹动  1-底部弹动
 */
function resetBV(type) {
  uexWindow.resetBounceView(type);
}

/**
 * 显示加载框
 * @param String mes 显示的提示信息语
 * @param String t  毫秒数 窗口存在时间 有的话显示框不显示那个“圈”，并且在t时间后消失
 */
function $toast(mes, t) {
  uexWindow.toast(t ? '0' : '1', '5', mes, t ? t : 0);
}

/**
 * 手动关闭加载框
 */
function $closeToast() {
  uexWindow.closeToast();
}

/**
 * getJSON请求数据的错误回调函数
 * @param {Object} err 返回的错误对象
 */
function getJSONError(err) {
  $closeToast();
  resetBV(0);
  resetBV(1);
  if (err.message == 'network error!') {
    alert('网络未连接');
  } else if (err.message == 'json parse failed!') {
    alert('json解析失败');
  } else if (err.message == 'file does not exist!') {
    alert('文件不存在');
  } else if (err.message == 'read file failed!') {
    alert('文件读取错误');
  } else {
    alert('发现未知错误');
  }
}


var dbname = "localdb",
  dbId = 0,
  userId = 500;




/**设置安卓back和menu按键事件监听
 * @b: back键，1为监听。
 * @m: menu键，1为监听。
 * @cb1: back键监听处理回调方法。
 * @cb2: menu键监听处理回调方法。
 */
function addKeyListener(b, m, cb1, cb2) {
  uexWindow.onKeyPressed = function(keyCode) {
    if (keyCode == 0) {
      if (cb1) cb1();
      //uexWidget.finishWidget(''); //退出应用
    } else {
      if (cb2) cb2();
    }
  }
  if (b) uexWindow.setReportKey('0', '1');
  if (m) uexWindow.setReportKey('1', '1');
}
/**
 * 时间选择
 */
function checked_day_time(id) {
  //var date = getNowFormatDate();
  var date = $$(id).innerHTML
  var dateArr = date.split("-");
  
  uexControl.openDatePicker(dateArr[0], dateArr[1], dateArr[2]);
  uexControl.cbOpenDatePicker = function(opId, dataType, data) {

    if (dataType == 1) {

      var obj = eval('(' + data + ')');
      var CurrentDate = "";

      var Year = obj.year;
      var Month = obj.month;
      var Day = obj.day;
      CurrentDate += Year + "-";
      if (Month >= 10) {
        CurrentDate += Month + "-";
      } else {
        CurrentDate += "0" + Number(Month)+ "-";
      }
      if (Day >= 10) {
        CurrentDate += Day;
      } else {
        CurrentDate += "0" + Day;
      }
      var dateTimeArr = date.split(" ");
      var dateTime = dateTimeArr[1].split(":");
      uexControl.openTimePicker(dateTime[0], dateTime[1]);
      uexControl.cbOpenTimePicker = function(opId, dataType, data) {
        var obj = eval('(' + data + ')');
        var hour = obj.hour;
        var minute = obj.minute;
        if (hour >= 10) {
          CurrentDate += " " + hour + ":";
        } else {
          CurrentDate += " 0" + hour + ":";
        }
        if (minute >= 10) {
          CurrentDate += minute;
        } else {
          CurrentDate += "0" + minute;
        }

        $$(id).innerHTML = CurrentDate;
      }

    }
  }
}
function checked_day(id) {
  //var date = getNowFormatDate();
  var date = $$(id).innerHTML
  var dateArr = date.split("-");
  //alert(dateArr);
  uexControl.openDatePicker(dateArr[0], dateArr[1], dateArr[2]);
  uexControl.cbOpenDatePicker = function(opId, dataType, data) {

    if (dataType == 1) {

      var obj = eval('(' + data + ')');
      var CurrentDate = "";

      var Year = obj.year;
      var Month = obj.month;
      var Day = obj.day;
      CurrentDate += Year + "-";
      if (Month >= 10) {
        CurrentDate += Month + "-";
      } else {
        CurrentDate +="0"+Number(Month)+ "-";
      }
      if (Day >= 10) {
        CurrentDate += Day;
      } else {
        CurrentDate += "0" + Day;
      }
      $$(id).innerHTML = CurrentDate;
    }
  }
}






/**
 * loading效果
 */
function closeLoading() {
  document.getElementById("zvmain").style.display = "none";
  document.getElementById("Loadbox").style.display = "none";
}

function Loading(time, cover) {
  var str = "";
  str = '<div id="zvmain"></div><div id="Loadbox">';
  str += '<div class="iBox-wrap" style="margin-top: -23px;"><div class="iBox-box iBox-green" style="width: 10em;"><div class="iBox-icon"></div><div class="iBox-msg iBox-noBtns"><b>请稍候...</b></div></div></div>';
  str += '</div>';
  str += '</div>';
  var a = document.createElement("div");
  a.innerHTML = str;
  document.body.insertBefore(a, null);

  if (cover == "1") {
    document.getElementById("zvmain").style.background = "#ffffff";
  }
  if (parseInt(time) > 0) {
    document.getElementById("zvmain").style.display = "block";
    document.getElementById("Loadbox").style.display = "block";
    setTimeout(function() {
      document.getElementById("zvmain").style.display = "none";
      document.getElementById("Loadbox").style.display = "none";
    }, time);
  }
  if (parseInt(time) < 0) {
    document.getElementById("zvmain").style.display = "none";
    document.getElementById("Loadbox").style.display = "none";
  }
  if (parseInt(time) == 0) {
    document.getElementById("zvmain").style.display = "block";
    document.getElementById("Loadbox").style.display = "block";
  }
}
/**
 * 设置json数据
 */
function setLocalJosn(wsdl, nameSpace, paras, values, method, winName, winUrl, SOAPType) {

  var value = values.split('|');
  $.ajax({
    url: 'http://172.31.64.34:8011/sdk10098/public/yddfMAS/zyh_PersonalCenterGetOperationByLocation?',
    type: "GET",
    data: {
      periodStart: value[0],
      periodEnd: value[1],
      siteName: value[2],
      location: value[3]
    },
    //dataType: "json",
    success: function(json) {
      //console.log(json);
      json = $.xml2json(json);
      //console.log(json);
      var jsonStr = JSON.stringify(json);
      localStorage.setItem("zvData", jsonStr);
      document.getElementById("zvmain").style.display = "none";
      document.getElementById("Loadbox").style.display = "none";
      if (winName != undefined) {
        monitoring_timeout(winName, winUrl);
      }
    },
    error: function(err) {
      alert("请求失败");
    }
  });

}


/**
 * 设置json数据
 */
function monitoring_timeout(winName, winUrl) //判断是否超时
{
  var monitoring_judge = localStorage.getItem("monitoring_judge")
  if (monitoring_judge != '1') {
    openNewWin(winName, winUrl);
  }
  localStorage.setItem("monitoring_judge", "")
}

function monitoringJosn(wsdl, nameSpace, paras, values, method, winName, winUrl, SOAPType,intelligent) //智能监控查询（第一次）
{
    if(intelligent === "intelligent"){
        var value = values.split('|');
        //http://172.31.64.34:8011/sdk10098/public/yddfMAS/zyh_PersonalCenterGetOperationByLocation?
        $.ajax({
            url: "http://172.31.64.34:8011/sdk10098/public/yddfMAS/zyh_PersonalCenterGetOperationByLocation?",
            type: "GET",                                     
            data: {
                periodStart: value[0],
                periodEnd: value[1],
                siteName: value[2],
                location: value[3]
            },
            //dataType: "json",
            success: function(json) {
          
                json = $.xml2json(json);
                //console.log(json);
                var jsonStr = JSON.stringify(json);
                localStorage.setItem("zvData", jsonStr);
                document.getElementById("zvmain").style.display = "none";
                document.getElementById("Loadbox").style.display = "none";
                if (winName != undefined) {
                    monitoring_timeout(winName, winUrl);
                }
            },
            error: function(err) {
            alert("请求失败");
            }
        });    
    }else{
        var jsonPage =[{
            'key':'wsdl',
            'type':'0',
            'value':wsdl
            },{
            'key':'KEY1',
            'type':'0',
            'value':'1'
            },{'key':'KEY2',
            'type':'0',
            'value':'1'
            },{
            'key':'KEY3',
            'type':'0',
            'value':'1'
            },{
            'key':'nameSpace',
            'type':'0',
            'value':nameSpace
            },{
            'key':'method',
            'type':'0',
            'value':method
            },{
            'key':'paras',
            'type':'0',
            'value':paras
            },{
            'key':'values',
            'type':'0',
            'value':values
            }];
        var SOAPTypeA = "yes";
        if(SOAPType!=""&&SOAPType!=undefined){
            SOAPTypeA = "no";
        }
        $.getJSON(UrlClient+"&SOAPType="+SOAPTypeA,function(json){
            var jsonStr = JSON.stringify(json);
            localStorage.setItem("zvData",jsonStr);
            document.getElementById("zvmain").style.display="none";
            document.getElementById("Loadbox").style.display="none";
            if(winName!=undefined){
                monitoring_timeout(winName, winUrl);
            }   
        },"json",function(e){
            alert("发生了什么错误")
        },"POST",jsonPage,false);

    }


}


/**
 *
 * @param {Object} wsdl
 * @param {Object} nameSpace
 * @param {Object} paras
 * @param {Object} values
 * @param {Object} method
 * @param {Object} winName
 * @param {Object} winUrl
 * @param {Object} SOAPType
 */

function setLocalJosnPage(wsdl, nameSpace, paras, values, method, url, conetnt_id) {
  //	var wsdl = Urlpassenger_informaton + "DataService.asmx?wsdl";
  //    var nameSpace = "http://tempuri.org/";
  //	var paras = "code|GroupId|dateStart|dateEnd";
  //	var values = code+'|'+GroupId+'|'+dateStart+'|'+dateEnd;
  //	var method = "GetLuFuDataByDateAndGroupId";
  var jsonPage = [{
      'key': 'wsdl',
      'type': '0',
      'value': wsdl
    }, {
      'key': 'KEY1',
      'type': '0',
      'value': '1'
    },
    {
      'key': 'KEY2',
      'type': '0',
      'value': '1'
    }, {
      'key': 'KEY3',
      'type': '0',
      'value': '1'
    }, {
      'key': 'nameSpace',
      'type': '0',
      'value': nameSpace
    }, {
      'key': 'method',
      'type': '0',
      'value': method
    }, {
      'key': 'paras',
      'type': '0',
      'value': paras
    }, {
      'key': 'values',
      'type': '0',
      'value': values
    }
  ];
  var SOAPTypeA = "yes";
  $.getJSON(UrlClient + "&SOAPType=" + SOAPTypeA, function(json) {
    var jsonStr = JSON.stringify(json);
    //alert("592行" + jsonStr);
    localStorage.setItem("zvData", jsontr);
    document.getElementById("zvmain").style.display = "none";
    document.getElementById("Loadbox").style.display = "none";
    //ueppscript("attendance_management","content","attendance_list("+page+")");
    ueppscript(url, "content", conetnt_id + "()");
  }, "json", function(e) {}, "POST", jsonPage, false);
}


/**
 * 设置带有内容转换的json数据
 */
function contentJosn(wsdl, nameSpace, paras, values, method, winName, winUrl, SOAPType) {
  //	var wsdl = Urlpassenger_informaton + "DataService.asmx?wsdl";
  //    var nameSpace = "http://tempuri.org/";
  //	var paras = "code|GroupId|dateStart|dateEnd";
  //	var values = code+'|'+GroupId+'|'+dateStart+'|'+dateEnd;
  //	var method = "GetLuFuDataByDateAndGroupId";
  var jsonPage = [{
      'key': 'wsdl',
      'type': '0',
      'value': wsdl
    }, {
      'key': 'KEY1',
      'type': '0',
      'value': '1'
    },
    {
      'key': 'KEY2',
      'type': '0',
      'value': '1'
    }, {
      'key': 'KEY3',
      'type': '0',
      'value': '1'
    }, {
      'key': 'nameSpace',
      'type': '0',
      'value': nameSpace
    }, {
      'key': 'method',
      'type': '0',
      'value': method
    }, {
      'key': 'paras',
      'type': '0',
      'value': paras
    }, {
      'key': 'values',
      'type': '0',
      'value': values
    }
  ];
  var SOAPTypeA = "yes";
  if (SOAPType != "" && SOAPType != undefined) {
    SOAPTypeA = "no";
  }

  $.getJSON(UrlClient + "&act=norep&SOAPType=" + SOAPTypeA, function(json) {
    var jsonStr = JSON.stringify(json);
    localStorage.setItem("zvData", jsonStr);
    document.getElementById("zvmain").style.display = "none";
    document.getElementById("Loadbox").style.display = "none";
    openNewWin(winName, winUrl);
  }, "json", function(e) {}, "POST", jsonPage, false);
}

/**
 * 设置当前页面json数据
 */
function currentJosn(wsdl, nameSpace, paras, values, method, SOAPType) {
  var jsonPage = [{
      'key': 'wsdl',
      'type': '0',
      'value': wsdl
    }, {
      'key': 'KEY1',
      'type': '0',
      'value': '1'
    },
    {
      'key': 'KEY2',
      'type': '0',
      'value': '1'
    }, {
      'key': 'KEY3',
      'type': '0',
      'value': '1'
    }, {
      'key': 'nameSpace',
      'type': '0',
      'value': nameSpace
    }, {
      'key': 'method',
      'type': '0',
      'value': method
    }, {
      'key': 'paras',
      'type': '0',
      'value': paras
    }, {
      'key': 'values',
      'type': '0',
      'value': values
    }
  ];
  var SOAPTypeA = "yes";
  if (SOAPType != "" && SOAPType != undefined) {
    SOAPTypeA = "no";
  }
  $.getJSON(UrlClient + "&SOAPType=" + SOAPTypeA, function(json) {
    var currentJosnStr = JSON.stringify(json);
    returnjson(currentJosnStr);
  }, "json", function(e) {}, "POST", jsonPage, false);
}

function getNowFormatDate() {
  var day = new Date();
  var Year = 0;
  var Month = 0;
  var Day = 0;
  var CurrentDate = "";
  //初始化时间
  //Year       = day.getYear();//有火狐下2008年显示108的bug
  Year = day.getFullYear(); //ie火狐下都可以
  Month = day.getMonth() + 1;
  Day = day.getDate();

  CurrentDate += Year + "-";
  if (Month >= 10) {
    CurrentDate += Month + "-";
  } else {
    CurrentDate += "0" + Month + "-";
  }
  if (Day >= 10) {
    CurrentDate += Day;
  } else {
    CurrentDate += "0" + Day;
  }
 
  //alert(CurrentDate);
  return CurrentDate;
}

function getNowFormatDateTime() {
  var day = new Date();
  var Year = 0;
  var Month = 0;
  var Day = 0;
  var hour = 0;
  var minute = 0;
  var CurrentDate = "";
  //初始化时间
  //Year       = day.getYear();//有火狐下2008年显示108的bug
  Year = day.getFullYear(); //ie火狐下都可以
  Month = day.getMonth() + 1;
  Day = day.getDate();
  hour = day.getHours();
  minute = day.getMinutes();
  CurrentDate += Year + "-";
  if (Month >= 10) {
    CurrentDate += Month + "-";
  } else {
    CurrentDate += "0" + Month + "-";
  }
  if (Day >= 10) {
    CurrentDate += Day;
  } else {
    CurrentDate += "0" + Day;
  }
  if (hour >= 10) {
    CurrentDate += " " + hour + ":";
  } else {
    CurrentDate += " 0" + hour + ":";
  }
  if (minute >= 10) {
    CurrentDate += minute;
  } else {
    CurrentDate += "0" + minute;
  }
  //alert(CurrentDate);
  return CurrentDate;
}

//标准过站时间
//function site_standard_time(Code)
//{
//	alert(Code)
//	$.getJSON(ceair_class_url, function(ajson){
//		var Coderes = jsonsql.query("select * from json.data.items where (Code=='"+Code+"') ", ajson);
//		alert(Coderes[0].TagName)
//		localStorage.setItem("zv_SelectArea",Coderes[0].TagName);
//	});
//}


//下拉菜单
function select1_val(pid, idname, selectval) //一级
{
  var selectval = selectval
  alert(selectval);
  $.getJSON(ceair_class_url, function(jjson) {
    var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
    for (var i = 0; i < res.length; i++) {
      selectval += '<option value="' + res[i].Code + '">' + res[i].Name + '</option>'
    }
    $$(idname).innerHTML = selectval;
  });
}
//二级联动下拉菜单
function select2_val(pid, idname, selectval, site_id) //一级
{

  var site_id = site_id;
  $.ajax({
    url: ceair_class_url,
    type: "GET",
    dataType: "JSON",
    success: function(jjson) {
      //jjson = JSON.parse(jjson);
      var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
      for (var i = 0; i < res.length; i++) {
        var selected_id = ''
        if (res[i].ID == site_id) {
          selected_id = ' selected'
        }

        selectval += '<option value="' + res[i].ID + '|' + res[i].Code + '" ' + selected_id + '>' + res[i].Name + '</option>'
      }
      $$(idname).innerHTML = selectval;
    }
  });
  //   $.getJSON(ceair_class_url, function(jjson) {
  //
  //     var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
  //     for (var i = 0; i < res.length; i++) {
  //       var selected_id = ''
  //       if (res[i].ID == site_id) {
  //         selected_id = ' selected'
  //       }
  //       alert(res[i].Name);
  //       selectval += '<option value="' + res[i].ID + '|' + res[i].Code + '" ' + selected_id + '>' + res[i].Name + '</option>'
  //     }
  //     $$(idname).innerHTML = selectval;
  //   });
}

function select_default_val(pid, idname, selectval, site_id) //默认二级
{
  $.getJSON(ceair_class_url, function(jjson) {
    var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
    for (var i = 0; i < res.length; i++) {
      var selected_id = ''
      if (res[i].ID == site_id) {
        selected_id = ' selected'
      }
      selectval += '<option value="' + res[i].ID + '|' + res[i].Code + '" ' + selected_id + '>' + res[i].Name + '</option>'
    }
    $$(idname).innerHTML = selectval;
  });
}

function select_default_val_bak(pid, idname, selectval, site_id) //默认二级
{
  $.getJSON(ceair_class_url, function(jjson) {
    var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
    for (var i = 0; i < res.length; i++) {
      var selected_id = ''
      if (res[i].ID == site_id) {
        selected_id = ' selected'
      }
      selectval += '<option value="' + res[i].Site + '" ' + selected_id + '>' + res[i].Name + '</option>'
    }
    $$(idname).innerHTML = selectval;
  });
}

function zv_linkage(id, default_id, select_id, default_val, select_val) { //二级
  var sl = document.getElementById(id);
  if (sl) {
    var sp = sl.parentElement; //<span>
    if (sp) {
      var ch = sp.getElementsByTagName("div")[0];
      var t = sl.options[sl.selectedIndex].text;
      if (ch) {
        ch.innerHTML = t;
      }
    }
  }
  $$(default_id).innerHTML = default_val
  var SiteName = $$(id).value;
  if (SiteName != '') {
    var pid = SiteName.split("|");
    pid = pid[0]
    select1_val(pid, select_id, select_val)
  } else {
    $$(select_id).innerHTML = select_val;
  }
}


function zv_linkageX(id, default_id, select_id, default_val, select_val) { //二级
  var extarea = localStorage.getItem("zv_SelectArea");
  localStorage.setItem("zv_SelectArea", "");
  $$("area").value = "";
  setarea("");

  var sl = document.getElementById(id);
  if (sl) {
    var sp = sl.parentElement; //<span>
    if (sp) {
      var ch = sp.getElementsByTagName("div")[0];
      var t = sl.options[sl.selectedIndex].text;
      if (ch) {
        ch.innerHTML = t;
      }
    }
  }
  $$(default_id).innerHTML = default_val
  var SiteName = $$(id).value;
  if (SiteName != '') {
    var pid = SiteName.split("|");
    pid = pid[0]
    select3_val(pid, select_id, select_val)
  } else {
    $$(select_id).innerHTML = select_val;
  }
  //console.log(selectval);
}

function select3_val(pid, idname, selectval) //一级
{ 
  var selectval = selectval
  $.getJSON(ceair_class_url, function(jjson) {
    var res = jsonsql.query("select * from json.data.items where (PID=='" + pid + "')  order by OrderBy asc", jjson);
    for (var i = 0; i < res.length; i++) {
      selectval += '<option value="' + res[i].Site + '">' + res[i].Name + '</option>'
    }
    console.log(selectval);
    $$(idname).innerHTML = selectval;
  });
}



//下载判断IOS、Android
function loadLiulan(URl) { //浏览器
  localStorage.setItem("attachment_url", URl);
  openNewWin('attachment', 'attachment.html')


  //	if(isAndroid)
  //	{
  //		uexWidget.loadApp("android.intent.action.VIEW", "text/html",URl);
  //	}
  //	else
  //	{
  //		uexWidget.loadApp("", "",URl);
  //	}

}
//返回主页面
function exitApp() {

  //	localStorage.setItem("ZV_EMPLOYEE_NUMBER","");
  //	localStorage.setItem("ZV_Account","");
  //	localStorage.setItem("ZV_UserName","");
  //	localStorage.setItem("ZV_Department","");
  localStorage.setItem("fly_zv_carrier", "");
  localStorage.setItem("fly_zv_flightNo", "");
  localStorage.setItem("fly_zv_pdate", "");
  localStorage.setItem("fly_zv_dept", "");
  localStorage.setItem("fly_zv_arr", "");
  localStorage.setItem("fly_zv_choose", "");
  //uexWindow.close(-1);
  uexWidget.finishWidget('');
}
//监听返回键返回主页面
function exitreturn() {
  var plat = uexWidgetOne.platformName;
  //如果是Android平台，则监听返回按钮事件
  if (plat == 'android') {
    uexWindow.onKeyPressed = function(keyCode) {
      if (keyCode == 0)
        uexWidget.finishWidget('');
    }
    uexWindow.setReportKey(0, 1);
  }
}

function goRoot() {
  uexWindow.onKeyPressed = function(keyCode) {
    if (keyCode == 0)
      uexWidget.finishWidget('');
  }
  uexWindow.setReportKey(0, 1);
}

//权限验证
function checkUserRole(UID, Code, callback) {
  var jsonPage = [{
    'key': 'RequestKey',
    'type': '0',
    'value': RequestKey
  }, {
    'key': 'act',
    'type': '0',
    'value': 'GetBtnCode'
  }, {
    'key': 'EMPLOYEE_NUMBER',
    'type': '0',
    'value': UID
  }, {
    'key': 'AppBtnCode',
    'type': '0',
    'value': Code
  }];
  $.getJSON(host_address_url + "GetUserInfo", function(json) {
    if (json == "false" || json == false) {
      //$alert("对不起，您没有该模块权限，请联系管理员： chengcheng1@ceair.com",winClose);
      openNewWin('prompt', 'prompt.html', -1);
    } else {
      callback();
    }
    return false;
  }, "str", function(e) {}, "POST", jsonPage, false);
  return false;
}
//登录账号领域验证
function checkAccountDomain() {
    ZV_EMPLOYEE_NUMBER="";
  //alert(ZV_EMPLOYEE_NUMBER);
  //判断该员工是否登录过，如果登录过就不需要登录了，否则就弹出登录界面
  if (ZV_EMPLOYEE_NUMBER == "" || ZV_EMPLOYEE_NUMBER == undefined || ZV_EMPLOYEE_NUMBER == null || ZV_EMPLOYEE_NUMBER == "null") {
    var username = localStorage['MU30-lOGIN-USRNAME'];
    var jsonPage = [{
      'key': 'act',
      'type': '0',
      'value': 'AccountDomain'
    }, {
      'key': 'Account',
      'type': '0',
      'value': username
    }];
    $.getJSON(host_address_url + "GetUserInfo", function(json) {
      if (json == "0" || json == 0) {
        openNewWin("login", "login.html", 0);
      } else {
        localStorage.setItem("ZV_EMPLOYEE_NUMBER", json);
      }
    }, "str", function(e) {
      alert(JSON.stringify(e))
    }, "POST", jsonPage, false);
  }
}
/////////////////////////////////////////////////////////////////////////////////////时间转换开始
function zv_transdate(endTime) { //北京时间转换时间戳
  var date = new Date();
  date.setFullYear(endTime.substring(0, 4));
  date.setMonth(endTime.substring(5, 7) - 1);
  date.setDate(endTime.substring(8, 10));
  date.setHours(endTime.substring(11, 13));
  date.setMinutes(endTime.substring(14, 16));
  date.setSeconds(endTime.substring(17, 19));
  return Date.parse(date) / 1000;
}
//var time =zv_transdate("2014-11-23 16:11:00")


function ceair_time(endTime) { //东航时间转换
  var strs = endTime.replace('T', ' '); //字符替换
  strs = strs.replace('Z', ''); //字符替换
  return strs;
}

function ceair_Greenwich_time(endTime) { //东航时间转换格林威治+8时间戳格式
  var strs = endTime.replace('T', ' '); //字符替换
  var endTime = strs.replace('Z', ''); //字符替换
  var date = new Date();
  date.setFullYear(endTime.substring(0, 4));
  date.setMonth(endTime.substring(5, 7) - 1);
  date.setDate(endTime.substring(8, 10));
  date.setHours(endTime.substring(11, 13));
  date.setMinutes(endTime.substring(14, 16));
  date.setSeconds(endTime.substring(17, 19));
  return Date.parse(date) / 1000 + 28800;
}
//var times =ceair_time("2004-11-23T16:11:00Z")

function zv_detailed(dateNum) { //时间戳转换北京时间
  var date = new Date(dateNum * 1000);
  return date.getFullYear() + "-" + fixZero(date.getMonth() + 1, 2) + "-" + fixZero(date.getDate(), 2) + " " + fixZero(date.getHours(), 2) + ":" + fixZero(date.getMinutes(), 2) + ":" + fixZero(date.getSeconds(), 2);

  function fixZero(num, length) {
    var str = "" + num;
    var len = str.length;
    var s = "";
    for (var i = length; i-- > len;) {
      s += "0";
    }
    return s + str;
  }
}
//var zv_detailed =zv_detailed("1416731652")

/////////////////////////////////////////////////////////////////////////////////////时间转换结束


function setLocalLocation(callback) {
  var uAddress = localStorage['uAddress'];
  //uAddress = "ddd&loc=陕西省西安市莲湖区";
  if (uAddress != undefined) {
    var uAddressArr = uAddress.split("loc=");

    uAddress = decodeURIComponent(uAddressArr[1]);
    if (uAddress.indexOf("省") > 0) {
      uAddressArr = uAddress.split("省");
      uAddress = uAddressArr[1];
      uAddressArr = uAddress.split("市");
      uAddress = uAddressArr[0];
    } else {
      uAddressArr = uAddress.split("市");
      uAddress = uAddressArr[0];
    }
    if (uAddress == undefined || uAddress == "" || uAddress == null) {
      uAddress = "上海";
    }

    setLocalAddress(uAddress, callback);
  } else {
    localStorage.setItem("Default_IATACode", "SHA");
    localStorage.setItem("Default_FullName", "上海虹桥");
    setLocalAddress("上海虹桥", callback);
  }
}

function setLocalAddress(uAddress, callback) {
  //alert(uAddress);
  uAddress = base64encode(utf16to8(uAddress))
  var jsonPage = [{
    'key': 'RequestKey',
    'type': '0',
    'value': RequestKey
  }, {
    'key': 'act',
    'type': '0',
    'value': 'Get_uAddress'
  }, {
    'key': 'key',
    'type': '0',
    'value': uAddress
  }];
  $.getJSON(host_address_url + "mobile_app.jsp", function(json) {
    var IATACode = "SHA";
    var FullName = "上海虹桥";
    if (json.IATACode == 'PVG') {
      IATACode = "SHA";
      FullName = "上海虹桥";
    } else {
      if (IATACode == "null" || IATACode == null || IATACode == "") {
        IATACode = "SHA";
        FullName = "上海虹桥";
      } else {
        IATACode = json.IATACode;
        FullName = json.FullName;
      }
    }
    localStorage.setItem("Default_IATACode", IATACode);
    localStorage.setItem("Default_FullName", FullName);
    callback(IATACode, FullName);
  }, "json", function(e) {}, "POST", jsonPage, false);
}

function setDefauleIATACodeCallback(Default_IATACode, Default_FullName) {
  $$("dept_code").innerHTML = Default_IATACode;
  $$("dept").innerHTML = Default_FullName;
}
